package cn.jvtc.course.management.system.controller;

import cn.jvtc.course.management.system.utils.InternetWorm;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import sun.misc.BASE64Encoder;

/**
 * ${DESCRIPTION}
 *
 * @author GaoFeng2017
 * @date 2017-12-07 13:21:24
 **/

@WebServlet(name = "GetClassTable", urlPatterns = {"/GetClassTable"})

public class GetClassTable extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String sessionId = request.getParameter("sid");
        String captcha = request.getParameter("captcha");

        try {
            int id = 0;
            do {
                id = InternetWorm.createTable(captcha,sessionId);
                request.setAttribute("id",id);
                request.setAttribute("sid",sessionId);
                request.setAttribute("flag",true);
                request.getRequestDispatcher("/get_class_table.jsp").forward(request,response);
                break;
            } while(id <= 500);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
